stdlib: remove comparison with EOF macro to comply with MISRA
authorJonathan Wright <[email protected]>
Tue, 6 Mar 2018 16:23:28 +0000 (16:23 +0000)
committerJonathan Wright <[email protected]>
Thu, 15 Mar 2018 13:32:54 +0000 (13:32 +0000)
Ensures compliance with MISRA C-2012 Rule 22.7

Change-Id: Ifbe0926a24ba0dca18174e1aa87313a63bba50fb
Signed-off-by: Jonathan Wright <[email protected]>
lib/stdlib/puts.c

index 693a6bff3df6a31d15980a9d4c07f3f8b1fee786..284cf8c52aab33c10b01e6b17d0022851a810eb9 100644 (file)
@@ -9,23 +9,17 @@
 int puts(const char *s)
 {
        int count = 0;
-       while(*s)
-       {
-               if (putchar(*s++) != EOF) {
-                       count++;
-               } else {
-                       count = EOF;
-                       break;
-               }
+       while(*s) {
+               if (putchar(*s++) == EOF)
+                       return EOF;
+               count++;
        }
 
        /* According to the puts(3) manpage, the function should write a
         * trailing newline.
         */
-       if ((count != EOF) && (putchar('\n') != EOF))
-               count++;
-       else
-               count = EOF;
+       if (putchar('\n') == EOF)
+               return EOF;
 
-       return count;
+       return count + 1;
 }